package com.example.studentop;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.studentop.domain.Student;
import com.orm.SugarContext;
import com.orm.SugarRecord;

//初始化和数据库版本 驼峰命名规则
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  Button b1,b2,b3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stu_orm);
        b1=findViewById(R.id.b1);
        b2=findViewById(R.id.b2);
        b3=findViewById(R.id.b2);
        SugarContext.init(this);
        /*b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sav();

            }
        });*/


    }

    public void sav()
    {
        Student s1=new Student("李强","20",7,"男");
        s1.save();
        Student.find(Student.class, "name = ? ", "李强");


    }
    public void fid()
    {
        Student s1= SugarRecord.findById(Student.class,0);


    }
    public void up()
    {
        Student s1= SugarRecord.findById(Student.class,0);

      s1.setNum("3434");

    }
    public void delete()
    {
        Student s1= SugarRecord.findById(Student.class,0);

        s1.delete();

    }

    @Override
    public void onClick(View v)
    {
       switch (v.getId())
        {
            case  R.id.b1:
                sav();
                break;
            case  R.id.b2:
                up();
                break;

            case  R.id.b3:
                delete();
                break;
        }
    }
}
